In relational database management systems (RDBMSs) implementing a query language such as SQL (Structured Query Language), it is known to support application defined cursors. A cursor is identified relative to a query result set in a relational database and is used to access the result set in a controlled row by row manner.
A database system may support user-defined routines such as stored procedures or user defined functions (STPs or UDFs). In a stored procedure, it is possible to include statements to open a cursor, fetch data and then have the procedure execution return to the application, leaving the cursor open. The application may be defined to fetch data using the cursor opened by the stored procedure. If the application again invokes the same stored procedure, then a second occurrence of the same cursor can potentially take place. However, when the stored procedure in this example attempts to open the cursor in the second invocation, the RDBMS may return an error: the system will interpret the second open request as an attempt to open an already open cursor.
This type of problem may potentially also occur where procedures or functions are able to invoke other procedures or functions or where a single function is potentially accessible by many different processing branches of an application at the same time. Where routines are executed in parallel by the same application, the attempt to open multiple cursors with the same name in those routines may cause errors in a database system.
Unless cursor identification is uniformly maintained both at the user or client layer and at the server layer, the above problems may occur at either the client side or the server side of a relational database system. The location where an error is declared will depend on where the database system resolves identification issues for cursor requests. Although database systems will typically treat the multiple opening of cursors with the same name as an error condition, as can be seen from the above, there are many cases where it is desirable to permit cursors with the same name to be opened.